/*
 * MParametros.java
 *
 * Created on 29 de agosto de 2007, 09:59 AM
 *
 * To change this template, choose Tools | Template Manager
 * and open the template in the editor.
 */
package ig.formato.modelo;

import ig.basic.util.IModelo;
import ig.formato.gui.app.PParametros;
import ig.formato.util.IGFormatoException;
import ig.formato.util.MasterConnection;
import java.util.ArrayList;
import java.util.Collection;

/**
 *
 * @author jsanchez
 */
public class MParametros implements IModelo {

    PParametros panel = null;
    ig.formato.dao.ParametrosDao parametrosDao = new ig.formato.dao.ParametrosDao();
    ig.formato.dto.ParametroDTO dto = null;
    /** Creates a new instance of MParametros */

    public MParametros(PParametros panel) {
        this.panel = panel;
    }

    public Collection buscar() throws IGFormatoException {
        return this.parametrosDao.buscarTodos();
    }

    public void guardar() throws IGFormatoException {
        try {
            parametrosDao.setAutoCommit(false);
            parametrosDao.guardar(this.dto);
            parametrosDao.commit();
        } catch (IGFormatoException e) {
            parametrosDao.rollback();
            throw e;
        }
    }

    public void modificar() throws IGFormatoException {
    }

    public void nuevo() throws IGFormatoException {
        dto = new ig.formato.dto.ParametroDTO();
    }

    public void eliminar() throws IGFormatoException {
        try {
            parametrosDao.setAutoCommit(false);
            this.parametrosDao.eliminar(dto.getId());
            this.parametrosDao.commit();
        } catch (IGFormatoException e) {
            this.parametrosDao.rollback();
            throw e;
        }
    }

    public void salir() throws IGFormatoException {
//        MasterConnection.getMasterConnection().closeConnectionMaster();
    }

    public void imprimir() throws IGFormatoException {
    }

    public java.sql.Connection getConectionMaster() throws java.sql.SQLException, ClassNotFoundException, Exception {
        return this.parametrosDao.getConnectionIgFormato();
    }

    public Object getTO() throws IGFormatoException {
        return this.dto;
    }

    public void cancelar() throws IGFormatoException {
        this.setId(this.dto.getId());
    }

    public void setId(Integer id) {
        if (id != null) {
            try {
                dto = (ig.formato.dto.ParametroDTO) this.parametrosDao.buscar(id);
            } catch (IGFormatoException ex) {
                ex.printStackTrace();
            }
        }
    }

    public void setClonar(boolean flag) {
    }

    public boolean isClonar() {
        return false;
    }
}
